﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Guru.Web.UI;
using Telerik.Web.UI;
using Guru.Web.Controls.Telerik;

public partial class UserControl_GridPager : GuruUserControl
{
    protected int[] PageSizes = new int[] { 10, 20, 30, 40, 50, 100 };

    protected GridPagerItem GridPager
    {
        get 
        {
            return this.Parent.Parent as GridPagerItem;
        }
    }
    protected GuruGrid OwnerGrid 
    {
        get
        {
            return GridPager.OwnerTableView.OwnerGrid as GuruGrid;
        }
    }
  
    protected override void OnPreRender(EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptInclude("UserControl_GridPager", ResolveUrl("~/Assets/Js/RadGridPager.js"));
        int totalRecords = int.Parse(this.uxHddSourceCount.Value);
        this.DoChangePageSize(totalRecords);
        if (totalRecords <= this.PageSizes[0])
        {
            this.uxChangePageIndex.Visible = this.uxChangePageSize.Visible = false;
        }
        else
        {
            this.uxChangePageIndex.Visible = this.uxChangePageSize.Visible = true;
        }
        base.OnPreRender(e);       
    }

    protected void DoChangePageSize(int noRecord)
    {
        this.uxPageSize.Items.Clear();
        for (int i = 0; i < this.PageSizes.Length; i++)
        {
            this.uxPageSize.Items.Add(new RadComboBoxItem(PageSizes[i].ToString(), PageSizes[i].ToString()));           
            if (this.PageSizes[i] >= noRecord)
            {                
                break;
            }
        }

        if (this.uxPageSize.FindItemByValue(uxHddPagesize.Value) != null)
            this.uxPageSize.SelectedValue = uxHddPagesize.Value;
        else if (this.uxPageSize.Items.Count > 0)
            this.uxPageSize.SelectedIndex = 0;
    }
}
